local hx__shuaijian = fk.CreateSkill({
  name = "hx__shuaijian",
})

hx__shuaijian:addEffect(fk.EventPhaseStart, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(hx__shuaijian.name) and player.phase == Player.Start
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local tos = room:askToChoosePlayers(player,{
      targets = room:getOtherPlayers(player, false),
      min_num = 1,
      max_num = 1,
      prompt = "你可以选择一名其他角色与其各失去1点体力",
      skill_name = hx__shuaijian.name
    })
    if #tos > 0 then
      event:setCostData(self, { tos = tos })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = event:getCostData(self).tos[1]
    room:loseHp(player, 1, hx__shuaijian.name)
    room:loseHp(to, 1, hx__shuaijian.name)
  end,
})

hx__shuaijian:addEffect(fk.HpChanged, {
  anim_type = "offensive",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(hx__shuaijian.name) and player:usedEffectTimes(self.name) < 1
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local tars = table.filter(room:getAlivePlayers(), function(p)
      return  p:getHandcardNum() > 0
    end)
    if #tars == 0 then return false end
    local tos = room:askToChoosePlayers(player,{
      targets = tars,
      min_num = 1,
      max_num = 1,
      prompt = "你可以选择一名角色视为对其使用一张【火攻】",
      skill_name = hx__shuaijian.name,
      cancelable = true,
    })
    if #tos > 0 then
      event:setCostData(self, { tos = tos })
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = event:getCostData(self).tos[1]
    room:useVirtualCard("fire_attack", nil, player, to, hx__shuaijian.name, true)
  end,
})

hx__shuaijian:addEffect(fk.HpChanged, {
  anim_type = "offensive",
  priority = 2,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(hx__shuaijian.name)
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:addPlayerMark(player, "@hx__shuaijian")
  end,
})

hx__shuaijian:addEffect("targetmod", {
  residue_func = function(self, player, skill, scope, card)
      if skill.trueName == "slash_skill" and player:hasSkill(hx__shuaijian.name) then
        return player:getMark("@hx__shuaijian")
      end
  end,
})

hx__shuaijian:addEffect("distance", {
  correct_func = function(self, from, to)
    if from:hasSkill(hx__shuaijian.name) then
      return -from:getMark("@hx__shuaijian")
    end
  end,
})

return hx__shuaijian
